namespace StoredProcedure.Models.Entity
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class Entity : DbContext
    {
        public Entity()
            : base("name=Entity")
        {
        }

        public virtual DbSet<Category> Categories { get; set; }
        public virtual DbSet<Huyen> Huyens { get; set; }
        public virtual DbSet<Product> Products { get; set; }
        public virtual DbSet<Tinh> Tinhs { get; set; }
        public virtual DbSet<Urer_lop> Urer_lop { get; set; }
        public virtual DbSet<User_store> User_store { get; set; }
        public virtual DbSet<Xa> Xas { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Tinh>()
                .Property(e => e.Name)
                .IsUnicode(false);

            modelBuilder.Entity<Urer_lop>()
                .Property(e => e.TenLop)
                .IsFixedLength();

            modelBuilder.Entity<Xa>()
                .Property(e => e.Name)
                .IsFixedLength();


            modelBuilder.Entity<Product>()
               .MapToStoredProcedures(p => p.Insert(sp => sp.HasName("sp_InsertStudent").Parameter(pm => pm.Name, "name").Result(rs => rs.Id, "Id"))
               .Update(sp => sp.HasName("sp_UpdateStudent").Parameter(pm => pm.Name, "name"))
               .Delete(sp => sp.HasName("sp_DeleteStudent").Parameter(pm => pm.Id, "Id"))
               );
        }
       

    }
}
